using System;
using System.Linq;
using System.Data;
using System.Collections.Generic;

namespace Green.AgileMapper
{
    public static partial class AgileMapperMapping
    {
        /// <summary>
        /// Green.AgileMapper.Test.ContactWayDto  Warp fromObj Green.AgileMapper.Test.ContactWay;
        /// </summary>
        /// <param name="domainObj">Green.AgileMapper.Test.ContactWay</param>
        /// <returns>Green.AgileMapper.Test.ContactWayDto</returns>
        public static Green.AgileMapper.Test.ContactWayDto Warp(this Green.AgileMapper.Test.ContactWay domainObj)
        {
            var fromObj = new Green.AgileMapper.Test.ContactWayDto();
            fromObj.Phone = domainObj.Phone;
            fromObj.Email = domainObj.Email;
            fromObj.QQ = domainObj.QQ;
            return fromObj;
        }

        /// <summary>
        /// Green.AgileMapper.Test.ContactWayDto  Warp domainObj Green.AgileMapper.Test.ContactWay;
        /// </summary>
        /// <param name="domainObj">Green.AgileMapper.Test.ContactWay</param>
        /// <returns>fromObj</returns>
        public static void Warp(this Green.AgileMapper.Test.ContactWayDto fromObj, Green.AgileMapper.Test.ContactWay domainObj)
        {
            if (fromObj == null)
            {
                return;
            }
            if (domainObj == null)
            {
                domainObj = new Green.AgileMapper.Test.ContactWay();
            }
            domainObj.Phone = fromObj.Phone;
            domainObj.Email = fromObj.Email;
            domainObj.QQ = fromObj.QQ;

        }

        /// <summary>
        /// Green.AgileMapper.Test.ContactWayDto collection Warp fromObj Green.AgileMapper.Test.ContactWay collection;
        /// </summary>
        /// <param name="form">Green.AgileMapper.Test.ContactWayDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.ContactWay collection</param>        
        public static List<Green.AgileMapper.Test.ContactWayDto> Warp(this IList<Green.AgileMapper.Test.ContactWay> domainObj)
        {
            List<Green.AgileMapper.Test.ContactWayDto> froms = new List<Green.AgileMapper.Test.ContactWayDto>();
            domainObj.ToList().ForEach(t =>
            {
                froms.Add(Warp(t));
            });
            return froms;
        }

        /// <summary>
        /// Green.AgileMapper.Test.ContactWayDto collection Warp domainObj Green.AgileMapper.Test.ContactWay collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.ContactWayDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.ContactWay collection</param>      
        public static void Warp(this IList<Green.AgileMapper.Test.ContactWayDto> fromObj, IList<Green.AgileMapper.Test.ContactWay> domainObj)
        {
            fromObj.Warp(domainObj, (fromObjItem, domainObjItem) => fromObjItem.Equals(domainObjItem), false);
        }

        /// <summary>
        /// Green.AgileMapper.Test.ContactWayDto collection Warp domainObj Green.AgileMapper.Test.ContactWay collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.ContactWayDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.ContactWay collection</param>
        /// <param name="isDeleteNotInFromItem">Delete the item that not in From collection</param>           
        public static void Warp(this IList<Green.AgileMapper.Test.ContactWayDto> fromObj, IList<Green.AgileMapper.Test.ContactWay> domainObj, bool isDeleteNotInFromItem)
        {
            fromObj.Warp(domainObj, (fromObjItem, domainObjItem) => fromObjItem.Equals(domainObjItem), isDeleteNotInFromItem);
        }

        /// <summary>
        /// Green.AgileMapper.Test.ContactWayDto collection Warp domainObj Green.AgileMapper.Test.ContactWay collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.ContactWayDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.ContactWay collection</param>
        /// <param name="equalPredicate">the from item equal to item expression</param>           
        public static void Warp(this IList<Green.AgileMapper.Test.ContactWayDto> fromObj, IList<Green.AgileMapper.Test.ContactWay> domainObj, Func<Green.AgileMapper.Test.ContactWayDto, Green.AgileMapper.Test.ContactWay, bool> equalPredicate)
        {
            fromObj.Warp(domainObj, equalPredicate, false);
        }

        /// <summary>
        /// Green.AgileMapper.Test.ContactWayDto collection Warp domainObj Green.AgileMapper.Test.ContactWay collection;
        /// </summary>
        /// <param name="fromObj">Green.AgileMapper.Test.ContactWayDto collection</param>
        /// <param name="domainObj">Green.AgileMapper.Test.ContactWay collection</param> 
        /// <param name="equalPredicate">the from item equal to item expression</param>      
        /// <param name="isDeleteNotInFromItem">Delete the item that not in From collection</param>     
        public static void Warp(this IList<Green.AgileMapper.Test.ContactWayDto> fromObj, IList<Green.AgileMapper.Test.ContactWay> domainObj, Func<Green.AgileMapper.Test.ContactWayDto, Green.AgileMapper.Test.ContactWay, bool> equalPredicate, bool isDeleteNotInFromItem)
        {
            if (fromObj == null)
            {
                return;
            }

            if (domainObj == null)
            {
                domainObj = new List<Green.AgileMapper.Test.ContactWay>();
            }

            fromObj.ToList().ForEach(fromObjItem =>
            {
                Green.AgileMapper.Test.ContactWay toItem = default(Green.AgileMapper.Test.ContactWay);
                if (equalPredicate != null)
                {
                    toItem = domainObj.SingleOrDefault(domainObjItem => equalPredicate(fromObjItem, domainObjItem));
                }
                if (toItem == null)
                {
                    toItem = new Green.AgileMapper.Test.ContactWay();
                    domainObj.Add(toItem);
                }
                Warp(fromObjItem, toItem);
            });

            if (isDeleteNotInFromItem)
            {
                domainObj.Where(domainObjItem => fromObj.FirstOrDefault(fromObjItem => equalPredicate(fromObjItem, domainObjItem)) == null)
                    .ToList().ForEach(t =>
                    {
                        domainObj.Remove(t);
                    });
            }
        }
    }
}